package com.tjbank.cssys.web.service.impl;

import com.alibaba.druid.support.json.JSONUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tjbank.cssys.domain.CkOrderLoanOutsourcing;
import com.tjbank.cssys.repository.CkOrderLoanOutsourcingMapper;
import com.tjbank.cssys.web.service.CkOrderLoanOutsourcingService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CkOrderLoanOutsourcingServiceImpl implements CkOrderLoanOutsourcingService {

    protected static final Logger logger = LoggerFactory.getLogger(CkOrderLoanOutsourcingServiceImpl.class);

    @Autowired
    private CkOrderLoanOutsourcingMapper ckOrderLoanOutsourcingMapper;


    @Override
    public PageInfo selectList(Map<String, Object> params) {
        logger.info("委外数据查询，参数：params="+ JSONUtils.toJSONString(params));

        int page = Integer.parseInt(params.getOrDefault("page", "1").toString());
        int pageSize = Integer.parseInt(params.getOrDefault("pageSize", "10").toString());
        PageHelper.startPage(page, pageSize);
        List<CkOrderLoanOutsourcing> datas = ckOrderLoanOutsourcingMapper.selectList(params);
        PageInfo<CkOrderLoanOutsourcing> pageInfo = new PageInfo<>(datas);

        logger.info("委外数据查询，结果：pageInfo="+ pageInfo.toString());
        return pageInfo;
    }

    @Override
    public void updateStatus(String ids,Byte t_status) {
        logger.info("委外数据更改处理状态，参数：ids="+ ids);

        if(StringUtils.isNotBlank(ids)){
            Map params = new HashMap<String,Object>();
            params.put("ids",ids.split(","));
            params.put("status",t_status);
            int res = ckOrderLoanOutsourcingMapper.updateStatus(params);

            logger.info("委外数据更改处理状态，结果：res="+ res);
        }

    }

    @Override
    public List<CkOrderLoanOutsourcing> selectByIds(String[] split) {

        return ckOrderLoanOutsourcingMapper.selectByIds(split);
    }

    @Override
    public CkOrderLoanOutsourcing selectByPrimaryKey(Integer id) {
        long l = new BigDecimal(id).longValue();
        return ckOrderLoanOutsourcingMapper.selectByPrimaryKey(l);

    }


}
